package com.example.demo.controller;

import com.example.demo.mapper.CompatibilityMapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/compat")
public class CompatibilityController {

	@Resource
	private CompatibilityMapper compatibilityMapper;

	@PostMapping("/date-default-table")
	public String createDateDefaultTable() {
		try {
			compatibilityMapper.createDateDefaultTable();
			return "OK";
		} catch (Exception e) {
			return "ERROR: " + e.getMessage();
		}
	}

	@PostMapping("/explicit-ts-table")
	public String createExplicitTsTable() {
		try {
			compatibilityMapper.createExplicitTimestampTable();
			return "OK";
		} catch (Exception e) {
			return "ERROR: " + e.getMessage();
		}
	}

	@PostMapping("/insert-null-ts")
	public String insertNullTimestamp() {
		try {
			compatibilityMapper.insertNullIntoTimestamp(System.currentTimeMillis());
			return "OK";
		} catch (Exception e) {
			return "ERROR: " + e.getMessage();
		}
	}

	@PostMapping("/with-cte-count")
	public String withCteCount() {
		try {
			int c = compatibilityMapper.withCteCount();
			return "COUNT=" + c;
		} catch (Exception e) {
			return "ERROR: " + e.getMessage();
		}
	}

	@PostMapping("/merge-into-example")
	public String mergeIntoExample() {
		try {
			compatibilityMapper.mergeIntoExample();
			return "OK";
		} catch (Exception e) {
			return "ERROR: " + e.getMessage();
		}
	}
}


